//
//  Request.m
//  LeagueOfLegend
//
//  Created by appying_wxj on 14-7-4.
//  Copyright (c) 2014年 appying_wxj. All rights reserved.
//

#import "Request.h"
#import "Reachability.h"
@implementation Request
static Request *_instance;

+(BOOL)checkNet{
    
	Reachability *netstatus=[Reachability reachabilityWithHostName:@"www.baidu.com"];
    
	if ([netstatus currentReachabilityStatus]==0) {
		UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"网络不通，请监测网络！" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定",nil];
		[alert show];
		return NO;//网络不通
	}
	return YES;//网络通
}


+(NSString *)requestData:(NSString *)getStr
{
    if (!_instance)
    {
        _instance = [[self alloc] init];
    }
    NSString *reqStr = [getStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:reqStr]];
    request.delegate = _instance;
    [request startAsynchronous];
    while (request.tag!=10086)
    {
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    }
    NSString *requestStr = [[NSString alloc] initWithData:[request responseData] encoding:NSUTF8StringEncoding];
    return requestStr;
}
#pragma mark - ASIHTTPRequestDelegate
- (void)requestFinished:(ASIHTTPRequest *)request
{
    request.tag = 10086;
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
    request.tag = 10086;
}

+(NSMutableArray *)JsonData:(NSString *)dataStr
{
    SBJSON *json = [[SBJSON alloc] init];
    
    NSMutableArray *bigArr = [json objectWithString:dataStr error:nil];
    return bigArr;
}
+(NSDictionary *)JsonDatas:(NSString *)dataStrs
{
    SBJSON *json = [[SBJSON alloc] init];
    
    NSDictionary *bigDic = [json objectWithString:dataStrs error:nil];
    return bigDic;
}
@end
